package mpcc.mpcc.activity.life_app;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mpcc.mpcc.activity.MPCCActivity;
import mpcc.mpcc.activity.R;
import mpcc.mpcc.activity.busi_presentation.ImageAdapter;
import mpcc.mpcc.activity.card_info.CardInfoActivity;
import mpcc.mpcc.base.BaseActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;

public class LifeAppActivity extends BaseActivity {

	private List<Map<String, Object>> mData;
	private Button returnBtn;

	public void generateData() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String requestStr = "10100003" + sdf.format(new Date());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("title", "1");
		map.put("lifeappid", "1");
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("title", "2");
		map.put("lifeappid", "2");
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("title", "3");
		map.put("lifeappid", "3");
		list.add(map);
		setmData(list);
	}

	public void setmData(List<Map<String, Object>> mData) {
		this.mData = mData;
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lifeapp);
		returnBtn = (Button) findViewById(R.id.returnAllBusi);
		GridView gridview = (GridView) findViewById(R.id.allbusinessgrid);

		gridview.setAdapter(new ImageAdapter(this));
		generateData();
		gridview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				String lifeappid = (String) mData.get(position).get(
						"lifeappid");
				showInfo(lifeappid);
			}

		});

		addChangeActListener(returnBtn, LifeAppActivity.this,
				MPCCActivity.class);

	}

	public void showInfo(String lifeappid) {

		ArrayList<String> arrClass = new ArrayList<String>();
		arrClass.add(lifeappid);
		Bundle bundle = new Bundle();
		bundle.putSerializable("lifeappidlist", arrClass);

		Intent intent = new Intent();
		intent.putExtras(bundle);

		intent.setClass(this, PayActivity.class);
		startActivity(intent);
	}
}
